import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main3 {

    //public static List<List<Integer>> ll;
    public static int n;
    public static int V;
    public static int[] arr;
    public static int ret;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        V = in.nextInt();
        n = in.nextInt();
        arr = new int[n];
        //ll = new ArrayList<>();
        ret = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        //List<Integer> l = new ArrayList<>();
        dfs(0, 0);
        System.out.println(V - ret);
    }

    public static void dfs(int i, int r) {
        if (i == n) {
            //ll.add(new ArrayList<>(l));
            if (r <= V) {
                ret = Math.max(ret, r);
            }
            return;
        }

        //l.add(arr[i]);
        //r += arr[i];
        dfs(i + 1, r);
        dfs(i + 1, r + arr[i]);
        //r -= arr[i];
        //l.remove((l.size() - 1));
    }
}